{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'d81a48c328d65282d4b3a62aebb54b59629570828e4c3b88c8ab8400b4b30908'"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "key = b\"ff49f5bb-e977c8243dddb85ae87dde5c\"\n",
    "import hmac\n",
    "import hashlib\n",
    "digester = hmac.HMAC(key, digestmod=hashlib.sha256)\n",
    "\n",
    "header=b'''{\"msg_id\":\"17563e371ad74228887bfcc5468986b4\",\"username\":\"username\",\"session\":\"78f96241dd144c06ad25cc03a2b89fdb\",\"msg_type\":\"kernel_info_request\",\"version\":\"5.2\"}'''\n",
    "parent=b'''{\"msg_id\":\"17563e371ad74228887bfcc5468986b4\",\"username\":\"username\",\"session\":\"78f96241dd144c06ad25cc03a2b89fdb\",\"msg_type\":\"kernel_info_request\",\"version\":\"5.2\"}'''\n",
    "metadata = b\"{}\"\n",
    "content = b''' {\n",
    "    \"status\" : \"ok\",\n",
    "    \"protocol_version\": \"5.3\",\n",
    "    \"implementation\": \"tcljupyter\",\n",
    "    \"implementation_version\": \"0.0.1\",\n",
    "    \"language_info\": {\n",
    "        \"name\": \"tcl\",\n",
    "        \"version\": \"8.6.10\",\n",
    "        \"mimetype\": \"txt/tcl\",\n",
    "        \"file_extension\": \".tcl\"\n",
    "    }\n",
    "}'''\n",
    "\n",
    "# for each message\n",
    "d = digester.copy()\n",
    "for serialized_dict in (header, parent, metadata, content):\n",
    "    d.update(serialized_dict)\n",
    "signature = d.hexdigest()\n",
    "signature"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
